﻿using System;
using ContainerHost.ServiceModel;

namespace ContainerHost.SM
{
    /// <summary>
    /// IContainer Implementation for StructureMap
    /// </summary>
    public class StructureMapContainerFacade : IContainer
    {
        private readonly StructureMap.Container _container; 

        /// <summary>
        /// Initializes a new instance of the StructureMapContainerFacade class.
        /// </summary>
        public StructureMapContainerFacade()
        {
            _container = new StructureMap.Container();
            _container.Configure(x =>
            {
                x.ForRequestedType<Contracts.IPersonRepository>().TheDefaultIsConcreteType<PersonRepository.SamplePersonRepository>();
                x.ForRequestedType<Contracts.IPersonService>().TheDefaultIsConcreteType<Service.PersonService>();
            });
        }

        #region IContainer Members

        public object Resolve(Type t)
        {
            return _container.GetInstance(t);
        }

        #endregion
    }
}
